package com.VolunteerPlatform.Controller;

import com.VolunteerPlatform.Entity.AdminInfo;
import com.VolunteerPlatform.Service.AdminService.AdminInfoService;
import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextImpl;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpSession;

/**
 * Created by DoveXL on 2018/12/4.
 */
@Controller
@RequestMapping(value = "/**")
public class IndexController {

    @Autowired
    private AdminInfoService adminInfoService;

    @RequestMapping(value="index",method = RequestMethod.GET)
    public ModelAndView User_LoginSuccess(HttpSession httpSession)
    {
        SecurityContextImpl securityContextImpl = (SecurityContextImpl) httpSession.getAttribute("SPRING_SECURITY_CONTEXT");
        String User = securityContextImpl.getAuthentication().getName();
        System.out.println(User);
        AdminInfo adminInfo = adminInfoService.findAdminByNameService(User);
        JSONObject userInfoObject = new JSONObject();
        userInfoObject.put("user_name",adminInfo.getUserName());
        userInfoObject.put("user_realname",adminInfo.getRealName());

        return new ModelAndView("/index","UserInfo",userInfoObject);
    }

    @RequestMapping(value="volunteer/BankInfo",method=RequestMethod.GET)
    public ModelAndView BankInfoPage(HttpSession httpSession)
    {
        SecurityContextImpl securityContextImpl = (SecurityContextImpl) httpSession.getAttribute("SPRING_SECURITY_CONTEXT");
        String User = securityContextImpl.getAuthentication().getName();
        System.out.println(User);
        AdminInfo adminInfo = adminInfoService.findAdminByNameService(User);
        JSONObject userInfoObject = new JSONObject();
        userInfoObject.put("user_name",adminInfo.getUserName());
        userInfoObject.put("user_realname",adminInfo.getRealName());

        return new ModelAndView("/volunteer/BankInfo","UserInfo",userInfoObject);
    }
    @RequestMapping(value="volunteer/PersonInfo",method=RequestMethod.GET)
    public ModelAndView PersonInfoPage(HttpSession httpSession)
    {
        SecurityContextImpl securityContextImpl = (SecurityContextImpl) httpSession.getAttribute("SPRING_SECURITY_CONTEXT");
        String User = securityContextImpl.getAuthentication().getName();
        System.out.println(User);
        AdminInfo adminInfo = adminInfoService.findAdminByNameService(User);
        JSONObject userInfoObject = new JSONObject();
        userInfoObject.put("user_name",adminInfo.getUserName());
        userInfoObject.put("user_realname",adminInfo.getRealName());

        return new ModelAndView("/volunteer/PersonInfo","UserInfo",userInfoObject);
    }
    @RequestMapping(value="volunteer/VolunteerInfo",method=RequestMethod.GET)
    public ModelAndView VolunteerInfoPage(HttpSession httpSession)
    {
        SecurityContextImpl securityContextImpl = (SecurityContextImpl) httpSession.getAttribute("SPRING_SECURITY_CONTEXT");
        String User = securityContextImpl.getAuthentication().getName();
        System.out.println(User);
        AdminInfo adminInfo = adminInfoService.findAdminByNameService(User);
        JSONObject userInfoObject = new JSONObject();
        userInfoObject.put("user_name",adminInfo.getUserName());
        userInfoObject.put("user_realname",adminInfo.getRealName());

        return new ModelAndView("/volunteer/VolunteerInfo","UserInfo",userInfoObject);
    }

    @RequestMapping(value="volunteer/VolunteerSign",method=RequestMethod.GET)
    public ModelAndView VolunteerSignPage(HttpSession httpSession)
    {
        SecurityContextImpl securityContextImpl = (SecurityContextImpl) httpSession.getAttribute("SPRING_SECURITY_CONTEXT");
        String User = securityContextImpl.getAuthentication().getName();
        System.out.println(User);
        AdminInfo adminInfo = adminInfoService.findAdminByNameService(User);
        JSONObject userInfoObject = new JSONObject();
        userInfoObject.put("user_name",adminInfo.getUserName());
        userInfoObject.put("user_realname",adminInfo.getRealName());

        return new ModelAndView("/volunteer/VolunteerSign","UserInfo",userInfoObject);
    }



    @RequestMapping(value="volunteer/HonorInfo",method=RequestMethod.GET)
    public ModelAndView HonorInfoPage(HttpSession httpSession)
    {
        SecurityContextImpl securityContextImpl = (SecurityContextImpl) httpSession.getAttribute("SPRING_SECURITY_CONTEXT");
        String User = securityContextImpl.getAuthentication().getName();
        System.out.println(User);
        AdminInfo adminInfo = adminInfoService.findAdminByNameService(User);
        JSONObject userInfoObject = new JSONObject();
        userInfoObject.put("user_name",adminInfo.getUserName());
        userInfoObject.put("user_realname",adminInfo.getRealName());

        return new ModelAndView("/volunteer/HonorInfo","UserInfo",userInfoObject);
    }

    @RequestMapping(value="report/PersonStatistics",method=RequestMethod.GET)
    public ModelAndView PersonStatisticsPage(HttpSession httpSession)
    {
        SecurityContextImpl securityContextImpl = (SecurityContextImpl) httpSession.getAttribute("SPRING_SECURITY_CONTEXT");
        String User = securityContextImpl.getAuthentication().getName();
        System.out.println(User);
        AdminInfo adminInfo = adminInfoService.findAdminByNameService(User);
        JSONObject userInfoObject = new JSONObject();
        userInfoObject.put("user_name",adminInfo.getUserName());
        userInfoObject.put("user_realname",adminInfo.getRealName());

        return new ModelAndView("report/BasicInfoStatistics","UserInfo",userInfoObject);
    }

    @RequestMapping(value="report/TeamStatistics",method=RequestMethod.GET)
    public ModelAndView TeamStatisticsPage(HttpSession httpSession)
    {
        SecurityContextImpl securityContextImpl = (SecurityContextImpl) httpSession.getAttribute("SPRING_SECURITY_CONTEXT");
        String User = securityContextImpl.getAuthentication().getName();
        System.out.println(User);
        AdminInfo adminInfo = adminInfoService.findAdminByNameService(User);
        JSONObject userInfoObject = new JSONObject();
        userInfoObject.put("user_name",adminInfo.getUserName());
        userInfoObject.put("user_realname",adminInfo.getRealName());

        return new ModelAndView("report/SingleVolunteerStatistics","UserInfo",userInfoObject);

    }

    @RequestMapping(value="report/TimeStatistics",method=RequestMethod.GET)
    public ModelAndView TimeStatisticsPage(HttpSession httpSession)
    {
        SecurityContextImpl securityContextImpl = (SecurityContextImpl) httpSession.getAttribute("SPRING_SECURITY_CONTEXT");
        String User = securityContextImpl.getAuthentication().getName();
        System.out.println(User);
        AdminInfo adminInfo = adminInfoService.findAdminByNameService(User);
        JSONObject userInfoObject = new JSONObject();
        userInfoObject.put("user_name",adminInfo.getUserName());
        userInfoObject.put("user_realname",adminInfo.getRealName());
        return new ModelAndView("report/TeamVolunteerStatistics","UserInfo",userInfoObject);
    }





    @RequestMapping(value="team/TeamInfo",method=RequestMethod.GET)
    public ModelAndView TeamInfoPage(HttpSession httpSession)
    {

        SecurityContextImpl securityContextImpl = (SecurityContextImpl) httpSession.getAttribute("SPRING_SECURITY_CONTEXT");
        String User = securityContextImpl.getAuthentication().getName();
        System.out.println(User);
        AdminInfo adminInfo = adminInfoService.findAdminByNameService(User);
        JSONObject userInfoObject = new JSONObject();
        userInfoObject.put("user_name",adminInfo.getUserName());
        userInfoObject.put("user_realname",adminInfo.getRealName());

        return new ModelAndView("/team/TeamInfo","UserInfo",userInfoObject);
    }

    @RequestMapping(value="system/DataBackup",method=RequestMethod.GET)
    public ModelAndView DataBackupPage(HttpSession httpSession)
    {
        SecurityContextImpl securityContextImpl = (SecurityContextImpl) httpSession.getAttribute("SPRING_SECURITY_CONTEXT");
        String User = securityContextImpl.getAuthentication().getName();
        System.out.println(User);
        AdminInfo adminInfo = adminInfoService.findAdminByNameService(User);
        JSONObject userInfoObject = new JSONObject();
        userInfoObject.put("user_name",adminInfo.getUserName());
        userInfoObject.put("user_realname",adminInfo.getRealName());

        return new ModelAndView("/system/DataBackup","UserInfo",userInfoObject);
    }

    @RequestMapping(value="system/AdminInfo",method=RequestMethod.GET)
    public ModelAndView AdminInfoPage(HttpSession httpSession)
    {
        SecurityContextImpl securityContextImpl = (SecurityContextImpl) httpSession.getAttribute("SPRING_SECURITY_CONTEXT");
        String User = securityContextImpl.getAuthentication().getName();
        System.out.println(User);
        AdminInfo adminInfo = adminInfoService.findAdminByNameService(User);
        JSONObject userInfoObject = new JSONObject();
        userInfoObject.put("user_name",adminInfo.getUserName());
        userInfoObject.put("user_realname",adminInfo.getRealName());

        return new ModelAndView("/system/AdminInfo","UserInfo",userInfoObject);

    }

}
